package com.zq.assistant.ui.widget.recyclerview.itemtouch;

import android.content.Context;
import android.support.v4.widget.ViewDragHelper;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

/**
 * Created by zhangqiang on 17-5-31.
 */

public class ClickTouch implements RecyclerView.OnItemTouchListener {

    private int mTouchSlop;
    private float mLastMotionX,mLastMotionY,mDownX,mDownY;
    private boolean mIsBeingDragged;

    public ClickTouch(Context context) {

        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

        float currX = e.getX();
        float currY = e.getY();

        switch (e.getAction()){

            case MotionEvent.ACTION_DOWN:

                mDownX = mLastMotionX = currX;
                mDownY = mLastMotionY = currY;
                mIsBeingDragged = false;
                break;
            case MotionEvent.ACTION_MOVE:

                float deltaX = mLastMotionX - currX;
                float deltaY = mLastMotionY - currY;
                if(Math.abs(deltaX) > mTouchSlop || Math.abs(deltaY) > mTouchSlop){

                    mIsBeingDragged = true;
                }
                break;
            case MotionEvent.ACTION_UP:

                if(Math.abs(mDownX - currX) < mTouchSlop)
                break;
        }
        return !mIsBeingDragged;
    }

    @Override
    public void onTouchEvent(RecyclerView rv, MotionEvent e) {

        switch (e.getAction()){

            case MotionEvent.ACTION_DOWN:

                break;
            case MotionEvent.ACTION_MOVE:

                break;
            case MotionEvent.ACTION_UP:
                break;
        }
    }

    @Override
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

    }

}
